package com.quik.web.front.mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import org.springframework.stereotype.Repository;

import com.quik.backend.mapper.BaseDao;
import com.quik.common.Constants;
import com.quik.entity.BizAlterWorkerLog;
import com.quik.entity.BizBilled;
import com.quik.entity.BizBilledPayment;
import com.quik.entity.BizBilling;
import com.quik.entity.BizBillingChessRoom;
import com.quik.entity.BizBillingItem;
import com.quik.entity.BizBillingRelatedItem;
import com.quik.entity.BizBillingService;
import com.quik.entity.BizInvoice;
import com.quik.entity.DtaProduct;
import com.quik.entity.VipAccount;
import com.quik.util.Tools;

/**
 * 功能说明：
 *     处理所有与帐单相关的数据化持久操作
 * @author Jenny
 *
 */
@Repository
@SuppressWarnings("unchecked")
public class ConsultBillingDao  extends BaseDao<Object>{

	public List findWorker(String workerNo, String workerName, Integer workerTypeId, String workerStatus, Integer intPage, Integer pageSize) throws  Exception{
		Map map = new HashMap(6);
		map.put("workerNo", workerNo == null ? null : workerNo.trim());
		map.put("workerName", workerName == null ? null : workerName.trim());
		map.put("workerTypeId", workerTypeId);
		map.put("workerStatus", workerStatus);
		map.put("currPage", (intPage - 1) * pageSize);
		map.put("pageSize", pageSize);
		
		List list = load("findWorker", map);
		return list;
	}

	/**
	 * 保存帐单（操作biz_billing表）
	 * @return
	 */
	public Integer addBizBilling(BizBilling bizBilling) throws Exception{
		this.add("addBizBilling", bizBilling);
		return bizBilling.getId();
	}
	
	/**
	 * 保存关联帐单项（操作biz_billing_related_item表）
	 * @param relatedItem
	 * @throws Exception
	 */
	public void addBizBillingRelatedItem(BizBillingRelatedItem relatedItem) throws Exception{
		this.add("addBizBillingRelatedItem", relatedItem);
	}
	
	/**
	 * 保存帐单明细项
	 * @param billingItem
	 * @throws Exception
	 */
	public void addBizBillingItem(BizBillingItem billingItem) throws Exception{
		this.add("addBizBillingItem", billingItem);
	}
	
	/**
	 * 根据帐单编号查询帐单ID
	 * @param billingNo
	 * @return
	 * @throws Exception
	 */
	public Integer findBillingIdByBillingNo(String billingNo) throws Exception{
		Integer id = (Integer)get("findBillingIdByBillingNo", billingNo);
		return id;
	}
	
	/**
	 * 根据帐单关联项及关联类型查询帐单ID
	 * @param tokenNo
	 * @return
	 * @throws Exception
	 */
	public Integer findBillingIdByItemNo(String itemNo, Integer itemType) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>(3);
		map.put("itemNo", itemNo);
		map.put("itemType", itemType);
		map.put("billingStatus", BizBilling.STATUS_ACTIVE);
		
		Integer id = (Integer)get("findBillingIdByItemNo", map);
		return id;
	}
	
	/**
	 * 更新帐单关联项的item_no
	 * @param itemNo  关联项号
	 * @param itemType 关联项类型
	 * @param billingStatus 帐单状态
	 * @param staffNo 操作员
	 * @throws Exception
	 */
	public void updateBizbillingRelatedItemNo(String itemNo, String newItemNo, Integer itemType, String billingStatus, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>(5);
		map.put("itemNo", itemNo);
		map.put("newItemNo", newItemNo);
		map.put("itemType", itemType);
		map.put("billingStatus", billingStatus);
		map.put("staffNo", staffNo);
		
		update("updateBizbillingRelatedItemNo", map);
	}

	/**
	 * 更新帐单明细项中的手牌号
	 * @param srcToken 原手牌号
	 * @param newToken 新手牌号
	 * @param billingStatus 帐单状态
	 * @param staffNo 操作员
	 * @throws Exception
	 */
	public void updateBizBillingItemTokenNo(String srcToken, String newToken, String billingStatus, String staffNo) throws Exception{
		Map<String, String> map = new HashMap<String, String>(4);
		map.put("tokenNo", srcToken);
		map.put("newTokenNo", newToken);
		map.put("billingStatus", billingStatus);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingItemTokenNo", map);
	}
	
	/**
	 * 更新帐单明细项中的房间号
	 * @param srcRoom  原房间号
	 * @param newRoom  新房间号
	 * @param billingStatus  帐单状态
	 * @param staffNo 操作员
	 * @throws Exception
	 */
	public void updateBizBillingItemRoomNo(String srcRoom, String newRoom, String billingStatus, String staffNo) throws Exception{
		Map<String, String> map = new HashMap<String, String>(4);
		map.put("roomNo", srcRoom);
		map.put("newRoomNo", newRoom);
		map.put("billingStatus", billingStatus);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingItemRoomNo", map);
	}
	
	/**
	 * 新增帐单明细棋牌类
	 * @param bizBillingChessRoom
	 * @throws Exception
	 */
	public void addBizBillingChessRoom(BizBillingChessRoom bizBillingChessRoom) throws Exception{
		this.add("addBizBillingChessRoom", bizBillingChessRoom);
	}
	
	/**
	 * 新增帐单明细服务类
	 * @param bizBillingService
	 * @throws Exception
	 */
	public void addBizBillingService(BizBillingService bizBillingService) throws Exception{
		this.add("addBizBillingService", bizBillingService);
	}
	
	/**
	 * 根据编号及编号类型查询帐单
	 * @param tokenNo
	 * @return
	 * @throws Exception
	 */
	public BizBilling findBillingByRelatedItem(String itemNo, Integer itemType) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("itemNo", itemNo);
		paramMap.put("itemType", itemType);
		paramMap.put("status", BizBilling.STATUS_ACTIVE);
		
		BizBilling billing = (BizBilling)get("findBillingByRelatedItem", paramMap);
		return billing;
	}
	
	/**
	 * 根据主帐单ID查询所有关联的帐单
	 * @param billingId
	 * @return
	 * @throws Exception
	 */
	public List findRelatedBillingByBillingId(Integer billingId) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("billingId", billingId);
		paramMap.put("itemType", BizBillingRelatedItem.ITEM_TYPE_BILLING);
		paramMap.put("status", BizBilling.STATUS_ACTIVE);
		
		List list = load("findRelatedBillingByBillingId", paramMap);
		return list;
	}
	
	/**
	 * 根据帐单ID查询关联的房间（包括主帐单及关联帐单）
	 * @param billingId
	 * @param itemType
	 * @return
	 * @throws Exception
	 */
	public List findRelateRoomByBillingId(Integer billingId) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("billingId", billingId);
		paramMap.put("itemType", BizBillingRelatedItem.ITEM_TYPE_ROOM);
		
		List roomList = load("findRelateRoomByBillingId", paramMap);
		return roomList;
	}
		
	/**
	 * 根据帐单查询关联的手牌（包括主帐单及关联帐单）
	 * @param billingId
	 * @return
	 * @throws Exception
	 */
	public List findRelateTokenByBillingId(Integer billingId) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("billingId", billingId);
		map.put("itemType", BizBillingRelatedItem.ITEM_TYPE_TOKEN);
		
		List tokenList = load("findRelateTokenByBillingId", map);
		return tokenList;
	}
	
	/**
	 * 根据帐单ID查询所有的棋牌类消费（包括主帐单及关联帐单）
	 * @param billingIdList
	 * @return
	 * @throws Exception
	 */
	public List findChessConsumeByBillingId(Integer billingId) throws Exception{
		Map paramMap = new HashMap();
		paramMap.put("billingId", billingId);
		paramMap.put("ifChessRoom", DtaProduct.OPTION_FOR_YES);
		paramMap.put("ifWorker", DtaProduct.OPTION_FOR_NO);
		paramMap.put("category", Tools.getSection(BizBillingItem.TABLE_NAME, 
				Constants.SYSTEM_CODE_ITEMSTATUS));
		
		List chessList = load("findChessConsumeByBillingId", paramMap);
		return chessList;
	}
	
	/**
	 * 根据帐单ID查询所有的服务类消费（包括主帐单及关联帐单）
	 * @param billingId
	 * @return
	 * @throws Exception
	 */
	public List findServiceConsumeByBillingId(Integer billingId) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("billingId", billingId);
		paramMap.put("ifChessRoom", DtaProduct.OPTION_FOR_NO);
		paramMap.put("ifWorker", DtaProduct.OPTION_FOR_YES);
		paramMap.put("category", Tools.getSection(BizBillingItem.TABLE_NAME, 
				Constants.SYSTEM_CODE_ITEMSTATUS));
		paramMap.put("subCategory", Tools.getSection(BizBillingService.TABLE_NAME, 
				Constants.SYSTEM_CODE_TURNTYPE));
		
		List serviceList = load("findServiceConsumeByBillingId", paramMap);
		return serviceList;
	}
	
	/**
	 * 根据帐单ID查询所有的非服务类及棋牌类消费（包括主帐单及关联帐单）
	 * @param billingId
	 * @return
	 * @throws Exception
	 */
	public List findOtherConsumeByBillingId(Integer billingId) throws Exception{
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("billingId", billingId);
		paramMap.put("ifChessRoom", DtaProduct.OPTION_FOR_NO);
		paramMap.put("ifWorker", DtaProduct.OPTION_FOR_NO);
		paramMap.put("category", Tools.getSection(BizBillingItem.TABLE_NAME, 
				Constants.SYSTEM_CODE_ITEMSTATUS));
		
		List otherList = load("findOtherConsumeByBillingId", paramMap);
		return otherList;
	}
	
	/**
	 * 根据关联项编号及类型查询帐单关联项
	 * @param itemNo
	 * @param itemType
	 * @return
	 * @throws Exception
	 */
	public BizBillingRelatedItem findBillingRelateItemByTermNo(String itemNo, Integer itemType) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("itemNo", itemNo);
		map.put("itemType", itemType);
		map.put("billingStatus", BizBilling.STATUS_ACTIVE);
		
		BizBillingRelatedItem item = (BizBillingRelatedItem)get("findBillingRelateItemByTermNo", map);
		return item;
	}
	
	/**
	 * 根据biz_billing_item的ID更新状态
	 * @param id
	 * @param status
	 * @throws Exception
	 */
	public void updateBizBillingItemStatusById(Integer id, String status, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingItemStatusById", map);
	}
	
	public void updateBizBillingItemServeStatusById(Integer id, String serveStatus, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("serveStatus", serveStatus);
		map.put("staffNo", staffNo);
		update("updateBizBillingItemServeStatusById", map);
	}
	
	/**
	 * 根据biz_billing_service的ID更新状态、技师、轮钟类型等信息
	 * @param subItemId
	 * @param status
	 * @param workerNo
	 * @param turnType
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingServiceInfoById(Integer id, String status, String workerNo, String turnType, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("workerNo", workerNo);
		map.put("turnType", turnType);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingServiceInfoById", map);
	}
	
	/**
	 * 根据技工编号更新技工状态
	 * @param workerNo
	 * @param status
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateWorkerStatusByWorkerNo(String workerNo, String status, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("workerNo", workerNo);
		map.put("status", status);
		map.put("staffNo", staffNo);
		
		update("updateWorkerStatusByWorkerNo", map);
	}
	
	/**
	 * 更新biz_billing_chess_room的开始时间
	 * @param id
	 * @param status
	 * @param startTime
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingChessRoomStartTime(Integer id, String status, Date startTime, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("startTime", startTime);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingChessRoomStartTime", map);
	}
	
	/**
	 * 更新biz_billing_chess_room的结束时间
	 * @param id
	 * @param status
	 * @param endTime
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingChessRoomEndTime(Integer id, String status, Date endTime, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("endTime", endTime);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingChessRoomEndTime", map);
	}
	
	/**
	 * 根据biz_billing_item的ID查询关联的产品信息
	 * @param itemId
	 * @return
	 */
	public DtaProduct findProductByItemId(Integer itemId){
		DtaProduct product = (DtaProduct)get("findProductByItemId", itemId);
		return product;
	}
	
	/**
	 * 根据biz_billing_service的开始时间
	 * @param id
	 * @param status
	 * @param startTime
	 * @param planEndTime
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingServiceStartTime(Integer id, String status, Date startTime, Date planEndTime, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("startTime", startTime);
		map.put("planEndTime", planEndTime);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingServiceStartTime", map);
	}
	
	/**
	 * 根据biz_billing_service的开始时间
	 * @param id
	 * @param status
	 * @param endTime
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingServiceEndTime(Integer id, String status, Date endTime, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("endTime", endTime);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingServiceEndTime", map);
	}
	
	/**
	 * 通过ID查询帐单明细项
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public BizBillingItem getBizBillingItemByItemId(Integer id) throws Exception{
		BizBillingItem item = (BizBillingItem)get("getBizBillingItemByItemId", id);
		return item;
	}
	
	/**
	 * 根据ID查询帐单服务项
	 * @param id
	 * @return
	 * @throws Exception
	 */
	public BizBillingService getBizBillingServiceById(Integer id) throws Exception{
		BizBillingService service = (BizBillingService)get("getBizBillingServiceById", id);
		return service;
	}
	
	/**
	 * 更新棋牌类状态
	 * @param id
	 * @param status
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingChessRoomStatus(Integer id, String status, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingChessRoomStatus", map);
	}
	
	/**
	 * 更新服务类状态
	 * @param id
	 * @param status
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingServiceStatus(Integer id, String status, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("status", status);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingServiceStatus", map);
	}
	
	/**
	 * 新增更换技师记录
	 * @param workerLog
	 * @throws Exception
	 */
	public void addAlterWorkerLog(BizAlterWorkerLog workerLog) throws Exception{
		add("addBizAlterWorkerLog", workerLog);
	}
	
	/**
	 * 查询已经关联帐单的主帐单
	 * @return
	 * @throws Exception
	 */
	public List findRelatedBillingList() throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", BizBilling.STATUS_ACTIVE);
		map.put("master", BizBilling.MASTER_YES);
		map.put("itemType", BizBillingRelatedItem.ITEM_TYPE_BILLING);
		
		List list = load("findRelatedBillingList", map);
		return list;
	}
	
	/**
	 * 查询手牌、房间关联的帐单
	 * @return
	 * @throws Exception
	 */
	public List findRelatingBillingList(String itemNo, String billingNo, Integer itemType) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", BizBilling.STATUS_ACTIVE);
		map.put("master", BizBilling.MASTER_YES);
		map.put("itemType", itemType);
		map.put("billingNo", billingNo);
		map.put("itemNo", itemNo);
		
		List list = load("findRelatingBillingList", map);
		return list;
	}
	
	/**
	 * 根据ITEM编号及类型判断所关联的帐单是否是主帐单
	 * @param itemNo
	 * @return
	 */
	public BizBilling getRelateBilling(String itemNo, Integer itemType) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("itemNo", itemNo.trim());
		map.put("itemType", itemType);
		map.put("status", BizBilling.STATUS_ACTIVE);
		
		BizBilling billing = (BizBilling)get("getRelateBilling", map);
		return billing;
	}
	
	/**
	 * 根据帐单编号更新帐单类型
	 * @param billingNo
	 * @throws Exception
	 */
	public void updateBizBillingType(String billingNo, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("billingNo", billingNo);
		map.put("master", BizBilling.MASTER_NO);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingType", map);
	}
	
	/**
	 * 根据帐单编号查询帐单
	 * @param billingNo
	 * @return
	 * @throws Exception
	 */
	public BizBilling getBillingByBillingNo(String billingNo, String status) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("billingNo", billingNo);
		map.put("status", status);
		
		BizBilling billing = (BizBilling)get("getBillingByBillingNo", map);
		return billing;
	}
	
	/**
	 * 根据帐单明细项ID查询帐单编号
	 * @param itemId
	 * @return
	 * @throws Exception
	 */
	public String getBillingNoByBizBillingItemId(Integer itemId) throws Exception{
		String billingNo = (String)get("getBillingNoByBizBillingItemId", itemId);
		return billingNo;
	}
	
	/**
	 * 消费项转出
	 * @param itemId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingItemTransfer(Integer itemId, Integer billingId, String remark, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("itemId", itemId);
		map.put("remark", remark);
		map.put("staffNo", staffNo);
		map.put("billingId", billingId);
		
		update("updateBizBillingItemTransfer", map);
	}
	
	/**
	 * 新增开票
	 * @param invoice
	 * @throws Exception
	 */
	public void addInvoice(BizInvoice invoice) throws Exception{
		add("addInvoice", invoice);
	}
	
	/**
	 * 设置biz_billing_item表的营业日
	 * @param businessDay
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingItemBusinessDay(String businessDay, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("businessDay", businessDay);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingItemBusinessDay", map);
	}
	
	/**
	 * 设置biz_billed表的营业日
	 * @param businessDay
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBilledBusinessDay(String businessDay, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("businessDay", businessDay);
		map.put("staffNo", staffNo);
		
		update("updateBizBilledBusinessDay", map);
	}
	
	/**
	 * 根据帐单ID更新帐单状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);
		
		update("updateBizBillingStatusByBillingId", map);
	}
	
	/**
	 * 根据帐单ID更新关联的房间状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateRoomStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);
		map.put("itemType", BizBillingRelatedItem.ITEM_TYPE_ROOM);
		
		update("updateRoomStatusByBillingId", map);
	}
	
	/**
	 * 根据帐单编号更新手牌状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateTokenStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);
		map.put("itemType", BizBillingRelatedItem.ITEM_TYPE_TOKEN);
		
		update("updateTokenStatusByBillingId", map);
	}
	
	/**
	 * 根据帐单编号更新帐单明细项状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingItemStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);		
		
		update("updateBizBillingItemStatusByBillingId", map);
	}
	
	/**
	 * 根据帐单编号更新棋牌项状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingChessRoomStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);		
		
		update("updateBizBillingChessRoomStatusByBillingId", map);
	}
	
	/**
	 * 根据帐单编号更新服务项状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateBizBillingServiceStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);		
		
		update("updateBizBillingServiceStatusByBillingId", map);
	}
	
	/**
	 * 根据帐单编号更新服务技师状态
	 * @param status
	 * @param billingId
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateWorkerStatusByBillingId(String status, Integer billingId, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", status);
		map.put("billingId", billingId);
		map.put("staffNo", staffNo);		
		
		update("updateWorkerStatusByBillingId", map);
	}
	
	/**
	 * 查询所有未结帐的帐单
	 * @return
	 * @throws Exception
	 */
	public List findActiveBillingList() throws Exception{
		List billingList = load("findActiveBillingList", BizBilling.STATUS_ACTIVE);
		return billingList;
	}
	
	/**
	 * 根据VIP号查询VIP帐户
	 * @param vipCard
	 * @return
	 * @throws Exception
	 */
	public VipAccount getVipAccount(String vipCard) throws Exception{
		VipAccount vipAccount = (VipAccount)get("getVipAccount", vipCard);
		return vipAccount;
	}
	
	/**
	 *  根据配置时间查询产品的时间价格
	 * @param productNo
	 * @return
	 * @throws Exception
	 */
	public List findProductPriceListByProductNo(String productNo, Integer productPriceType) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("productNo", productNo);
		map.put("productPriceType", productPriceType);
		
		List list = load("findProductPriceListByProductNo", map);
		return list;
	}
	
	/**
	 * 根据产品编号查询产品
	 * @param productNo
	 * @return
	 * @throws Exception
	 */
	public DtaProduct getProductByNo(String productNo) throws Exception{
		DtaProduct product = (DtaProduct)get("getProductByNo", productNo);
		return product;
	}
	
	/**
	 * 更新结帐信息
	 * @param billed
	 * @throws Exception
	 */
	public void addBizBilled(BizBilled billed) throws Exception{
		add("addBizBilled", billed);
	}
	
	/**
	 * 结帐后更新帐单明细项信息
	 * @param billingItem
	 * @throws Exception
	 */
	public void updateBizBillingItemInfo(BizBillingItem billingItem) throws Exception{
		update("updateBizBillingItemInfo", billingItem);
	}
	
	/**
	 * 更新付款方式
	 * @param billedPayment
	 * @throws Exception
	 */
	public void addBizBilledPayment(BizBilledPayment billedPayment) throws Exception{
		add("addBizBilledPayment", billedPayment);
	}
	
	/**
	 * 更新会员帐户金额及积分
	 * @param vipCard
	 * @param currVipAmount
	 * @param vipPoint
	 * @param staffNo
	 * @throws Exception
	 */
	public void updateVipAccount(String vipCard, Integer currVipAmount, Integer vipPoint, String staffNo) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("vipCard", vipCard);
		map.put("currVipAmount", currVipAmount);
		map.put("vipPoint", vipPoint);
		map.put("staffNo", staffNo);
		
		update("updateVipAccountAmountAndPoint", map);
	}
	
	/**
	 * 根据帐单编号查询帐单关联项   
	 * @param billingId
	 * @return
	 * @throws Exception
	 */
	public List findBizBillingRelatedItemListByBillingId(String billingId) throws Exception{
		return load("findBizBillingRelatedItemListByBillingId", billingId);
		
	}
	
	public BizBilling findBillingById(String billingId) throws Exception{
		List<BizBilling> list =  load("findBillingById", billingId);
		if(list==null||list.size()<1) return null;
		return list.get(0);
	}
	public BizBilling findBillingByTokenNo(String tokenNo) throws Exception{
		List<BizBilling> list =  load("findBillingByTokenNo", tokenNo);
		if(list==null||list.size()<1) return null;
		return list.get(0);
	}

	public List<BizBillingItem> findBillingItemByBillingId(String billingId) throws Exception{
		return load("findBillingItemByBillingId", billingId);
	}
	public void updateBizBillingItemByFull(BizBillingItem bizBillingItem)throws Exception{
		String sql = "update"+bizBillingItem.getClass().getSimpleName()+"ByFull";
		update(sql, bizBillingItem);
	}
}


